import handler
from models import directories

class ListDir(handler.BasicHandler):
    def run(self, app, input):
        self.input = input
        if 'directory' not in self.input: return { 'error': 'InvalidArguments' }

        result = directories.get_by_hierarchical_path(self.input['directory'])
        if result is None: return { 'error' : 'DirectoryNotExists' }
        result['directory'] = result['directory'].serialize()
        result['content'] = map(lambda item: item.serialize(), result['content'])

        return result
